package org.dcarew.clearcase;


import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

// hide the .db files
// hide the .dat file


/**
 * The activator class controls the plug-in life cycle.
 */
public class CCPlugin extends AbstractUIPlugin
{
    // The plug-in ID
    public static final String PLUGIN_ID = "org.dcarew.clearcase";
    
    // The shared instance
    private static CCPlugin    plugin;
    
    private static Map<String, Image> imageMap  = new HashMap<String, Image>();
    
    
    
    
    /**
     * The constructor
     */
    public CCPlugin()
    {
    }





    public void start(BundleContext context) throws Exception
    {
        super.start(context);
        
        plugin = this;
    }





    public void stop(BundleContext context) throws Exception
    {
        plugin = null;
        
        super.stop(context);
    }





    /**
     * Returns the shared instance
     * 
     * @return the shared instance
     */
    public static CCPlugin getPlugin()
    {
        return plugin;
    }

    /**
     * Get a image from this plugin's icons directory.
     * 
     * @param imagePath the image path, relative to the icons directory.
     * @return the specified image
     */
    public static Image getImage(String imagePath)
    {
        if (imageMap.get(imagePath) == null)
        {
            ImageDescriptor imageDescriptor = imageDescriptorFromPlugin(PLUGIN_ID, "icons/" + imagePath);

            imageMap.put(imagePath, imageDescriptor.createImage());
        }

        return imageMap.get(imagePath);
    }





    /**
     * Get a image descriptor from this plugin's icons directory.
     * 
     * @param imagePath the image path, relative to the icons directory.
     * @return the specified image descriptor
     */
    public static ImageDescriptor getImageDescriptor(String imagePath)
    {
        return imageDescriptorFromPlugin(PLUGIN_ID, "icons/" + imagePath);
    }





    /**
     * Write the given exception to the Eclipse .log file.
     * 
     * @param exception the exception to write
     */
    public static void log(Throwable exception)
    {
        getPlugin().getLog().log(
                new Status(IStatus.ERROR, PLUGIN_ID, exception.toString(), exception));
    }

}
